package com.hl.card.modular.pack.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hl.card.common.constant.factory.PageFactory;
import com.hl.card.common.persistence.dao.IntegrateMapper;
import com.hl.card.common.persistence.model.Integrate;
import com.hl.card.modular.pack.service.IntegrateService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
/**
 * <p>
 * 积分入户 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2019-01-18
 */
@Service
public class IntegrateServiceImpl extends ServiceImpl<IntegrateMapper, Integrate> implements IntegrateService {
    @Override
    public int count(Integrate integrate) {
        int count=0;
        if(integrate==null){
            return count;
        }
        switch  (integrate.getEducation()){
            case 1://高中及以下 0
                break;
            case 2://中转0
                break;
            case 3://非全日制大专
                count=count+60;
                break;

            case 4://非全日制本科
                count=count+80;
                break;

            case 5://全日制大专
                count=count+70;
                break;
            case 6://全日制本科
                count=count+90;
                break;
            case 7://全日制研究生及以上
                count=count+100;
                break;
        }
        switch (integrate.getAge()) {
            case 1://18-35岁  5分
                count = count + 5;
                break;
            case 2://35-40岁 0分
                break;
            case 3://40岁  2分
                count = count - 2;
                break;
            case 4://41岁  4分
                count = count - 4;
                break;
            case 5://42岁  6分
                count = count -6;
                break;
            case 6://43岁  8分
                count = count - 8;
                break;
            case 7://44岁  10分
                count = count - 10;
                break;
            case 8://45岁 12分
                count = count - 12;
                break;
        }
        switch (integrate.getSbYears()) {
            case 1:
                count = count + 7;
                break;
            case 2:
                count = count + 14;
                break;
            case 3:
                count = count + 21;
                break;
            case 4:
                count = count + 28;
                break;
            case 5:
                count = count +30;
                break;
            case 6:
                break;
        }
        return count;
    }
    @Override
    public Page<Integrate> selectMultiCondition(Integrate integrate, String beginTime, String endTime) {
        Page<Integrate> page = new PageFactory<Integrate>().defaultPage();
        Wrapper<Integrate> wrapper = new EntityWrapper<>();
        wrapper.orderBy("create_time",false);
        if(!StringUtils.isEmpty(beginTime)){
            wrapper.ge("create_time",beginTime.trim());
        }
        if(!StringUtils.isEmpty(endTime)){
            System.out.println("endTime:"+endTime);
            wrapper.le("create_time",endTime.trim());
        }
        if (!StringUtils.isEmpty(integrate.getName())) {
            wrapper.eq("name", integrate.getName().trim());
        }
        if (!StringUtils.isEmpty( integrate.getAccount())) {
            wrapper.eq("account", integrate.getAccount().trim());
        }
        if(!StringUtils.isEmpty(integrate.getPhone())){
            wrapper.eq("phone",integrate.getPhone().trim());
        }
        Page<Integrate> dPage = selectPage(page, wrapper);
        return dPage;
    }
}
